package com.matt.controller.web;

import com.google.common.collect.ImmutableMap;
import com.matt.domain.TeachingTemplete;
import com.matt.domain.TeachingTempleteArea;
import com.matt.foundation.constant.TeachingTempleteConstant;
import com.matt.commons.dto.sso.StaffDTO;;
import com.matt.commons.model.StatusResponse;
import com.matt.foundation.model.MemVerificationCache;
import com.matt.service.remoteCall.SsoCallService;
import com.matt.service.TeachingTempleteService;

import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Describle This Class Is 通用模板管理
 * @Author ZengMin
 * @Date 2018/12/19 15:20
 * @Company Matt
 */
@RestController
@RequestMapping("/web/teaching_templete")
public class WebTeachingTempleteController {

    @Autowired
    TeachingTempleteService teachingTempleteService;

    @Autowired
    SsoCallService ssoCallService;

    @Autowired
    MemVerificationCache cache;


    @RequestMapping("/types")
    @ApiOperation(value = "取所有类型",httpMethod = "POST")
    public StatusResponse getAllType() {
        return StatusResponse.success(ImmutableMap.of("module", TeachingTempleteConstant.MODULE.getAll(), "pad_childType", TeachingTempleteConstant.PAD.getAll(),
                "course_childType", TeachingTempleteConstant.COURSE.getAll(), "course_common", TeachingTempleteConstant.COURSE_COMMON.getAll(),
                "course_flows", TeachingTempleteConstant.COURSE_FLOW.getAll()));
    }

    @ApiOperation(value = "保存模板",httpMethod = "POST")
    @RequestMapping("/save_templete")
    public StatusResponse saveTemplete(@RequestHeader String ticket, @RequestBody TeachingTemplete teachingTemplete) {
        Integer type = teachingTemplete.getExecType();  //1新增 2更新
        StaffDTO baseInfo = cache.getStaff(ticket);
        teachingTemplete.setCreateStaffId(baseInfo.getId());
        teachingTemplete.setCreateStaffName(baseInfo.getRealName());
        return StatusResponse.success(teachingTempleteService.saveTemplete(teachingTemplete, type));
    }

    @ApiOperation(value = "取所有模板",httpMethod = "POST")
    @RequestMapping("/get_templete_all")
    public StatusResponse getTemplete() {
        List<TeachingTemplete> templeteAll = teachingTempleteService.getTempleteAll();
        return StatusResponse.success(templeteAll);
    }

    @ApiOperation(value = "取当前模板详细（编辑模板时使用）",httpMethod = "POST")
    @RequestMapping("/get_templete_detail")
    public StatusResponse getTemplete(@RequestParam(required = true) String templeteId) {
        return StatusResponse.success(teachingTempleteService.getTempleteDetail(templeteId));
    }

    @ApiOperation(value = "绑定园区",httpMethod = "POST")
    @RequestMapping("/bind_area")
    public StatusResponse bindArea(@RequestBody List<TeachingTempleteArea> teachingTempleteArea) {
        return StatusResponse.success(teachingTempleteService.bindArea(teachingTempleteArea));
    }

    @ApiOperation(value = "取当前模板关联园区",httpMethod = "POST")
    @RequestMapping("/get_templete_area")
    public StatusResponse getBindArea(@RequestParam(required = true) String templeteId) {
        return StatusResponse.success(teachingTempleteService.getBindArea(templeteId));
    }

    @ApiOperation(value = "取当前园区关联模板",httpMethod = "POST")
    @RequestMapping("/get_templete_by_area")
    public StatusResponse getTempleteByArea(@RequestParam(required = true) String areaId) {
        return StatusResponse.success(teachingTempleteService.getTempleteByArea(areaId));
    }

    @ApiOperation(value = "查询模板下的子模块",httpMethod = "POST")
    @RequestMapping("/get_templete_by_type")
    public StatusResponse getTempleteByType(@RequestParam(required = true) String templeteId,@RequestParam(required = true)  Integer type) {
        return StatusResponse.success(teachingTempleteService.getTempleteByType(templeteId, type));
    }

    @ApiOperation(value = "删除模板",httpMethod = "POST")
    @RequestMapping("/del_templete")
    public StatusResponse delTeachingTemplete(@RequestParam(required = true) String templeteId) {
        return StatusResponse.success(teachingTempleteService.delTeachingTemplete(templeteId));
    }

    @ApiOperation(value = "删除模板子类型",httpMethod = "POST")
    @RequestMapping("/del_templete_detail")
    public StatusResponse delTeachingDetail(@RequestParam(required = true) String id) {
        return StatusResponse.success(teachingTempleteService.delTeachingDetail(id));
    }

}
